package com.wvToolTest;

import java.io.FileWriter;

import edu.udo.cs.wvtool.config.WVTConfiguration;
import edu.udo.cs.wvtool.config.WVTConfigurationFact;
import edu.udo.cs.wvtool.generic.output.WordVectorWriter;
//import edu.udo.cs.wvtool.generic.stemmer.DummyStemmer;
import edu.udo.cs.wvtool.generic.stemmer.LovinsStemmerWrapper;
import edu.udo.cs.wvtool.generic.stemmer.PorterStemmerWrapper;
import edu.udo.cs.wvtool.generic.stemmer.WVTStemmer;
import edu.udo.cs.wvtool.generic.vectorcreation.TFIDF;
import edu.udo.cs.wvtool.generic.wordfilter.StopWordsWrapper;
import edu.udo.cs.wvtool.main.WVTDocumentInfo;
import edu.udo.cs.wvtool.main.WVTFileInputList;
import edu.udo.cs.wvtool.main.WVTool;
import edu.udo.cs.wvtool.util.WVToolException;
import edu.udo.cs.wvtool.wordlist.WVTWordList;

public class Main {
	/**
	 * @param args
	 * @throws WVToolException 
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		WVTool wvt = new WVTool(false);
		WVTConfiguration config = new WVTConfiguration();

		System.out.println("Begin!");
		final WVTStemmer stemmer = new PorterStemmerWrapper();// TODO test
		final WVTStemmer lovingsStemmer = new LovinsStemmerWrapper();// lovings
																	// stemmer
		StopWordsWrapper filter = new StopWordsWrapper();

		config.setConfigurationRule(WVTConfiguration.STEP_STEMMER,
				new WVTConfigurationFact(lovingsStemmer));
		config.setConfigurationRule(WVTConfiguration.STEP_WORDFILTER,
				new WVTConfigurationFact(filter));
		//for (int k = 0; k < 17; ++k)
		{
			WVTFileInputList list = new WVTFileInputList(0);

			for (int i = 0; i < 16980; ++i)
			{
				if(i > 16979)
					break;
				list.addEntry(new WVTDocumentInfo("result/" + String.valueOf(i) + ".txt", "txt", "UTF-8",
						"english", 0));
			}
			System.out.println("In the middle!");
			WVTWordList wordList = null;		
			wordList = wvt.createWordList(list, config);

			// TODO prune frequency
			
			wordList.storePlain(new FileWriter("wordlist.txt"));
			wordList.store(new FileWriter("wordVector.txt"));

			FileWriter outFile = null;

			outFile = new FileWriter("wv.txt");

			WordVectorWriter wvw = new WordVectorWriter(outFile, true);
			config.setConfigurationRule(WVTConfiguration.STEP_OUTPUT,
					new WVTConfigurationFact(wvw));

			config.setConfigurationRule(WVTConfiguration.STEP_VECTOR_CREATION,
					new WVTConfigurationFact(new TFIDF()));

			wvt.createVectors(list, config, wordList);

			// Close the output file
			wvw.close();
			outFile.close();
			System.out.println("Finished!");
		}
		

	}

}
